<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
<body>
	<p>停车场分区</p>
	<a href="addZoneParking.jsp">添加分区</a>
	<table id="zoneParkingTab" border="1px" cellpadding="0px" cellspacing="0px">
	</table>
</body>
<script type="text/javascript">
	$(function(){
		showZoneParking();
		function showZoneParking(){
			$("#zoneParkingTab").html("");
			$.ajax({
				url:'findallzoneparking',
				method:'get',
				contentType:'application/json',
				dataType:'json',
				success:function(data){
					var tr = "<tr><th>ID</th><th>分区名</th><th>总车位数</th><th>操作</th></tr>";
					$("#zoneParkingTab").append(tr);
					$.each(data,function(){
						tr = "<tr><td>"+this.zoneParkingId+"</td><td>"+this.zoneParkingName+"</td><td>"+this.total+"</td>"+
							 "<td><a href='updateZoneParking.jsp?id="+this.zoneParkingId+"&name="+this.zoneParkingName+"&total="+this.total+"'>修改</a>/<a href='javascript:void(0);' id='"+this.zoneParkingId+"'>删除</a></td></tr>";
						$("#zoneParkingTab").append(tr);
						var id=this.zoneParkingId
						var id_ = "#"+id;
						$(id_).click(function(){
							$.ajax({
								url:'deletezoneparking',
								method:'get',
								contentType:'application/json',
								dataType:'json',
								data:{'zoneParkingId':id},
								success:function(data){
									showZoneParking();
								}
							})
						});
					});
				}
			});
		}
	})
</script>
</html>